<template>
	<div class="mobile">
		<div class="nav-top">
			<div class="left" @click="back()">
				<img src="../../../assets/img/phone-back.png" alt="">
			</div>
			<div class="right">
				<span>注册</span>
				<img src="../../../assets/img/phone-more.png" alt="">
			</div>
		</div>
		<div class="input-box">
			<div class="input">
				<div class="name">姓名</div>
				<input type="text" placeholder="请输入姓名" v-model="name">
			</div>
			<div class="input">
				<div class="name">账号</div>
				<input type="text" placeholder="请输入账号" v-model="username">
			</div>
			<div class="input">
				<div class="name">登录密码</div>
				<input type="password" placeholder="请输入密码" v-model="rePassword">
			</div>
			<div class="input">
				<div class="name">确认密码</div>
				<input type="password" placeholder="请再次输入密码" v-model="password">
			</div>
			<div class="input">
				<div class="name">手机号码</div>
				<input type="number" placeholder="请输入手机号" v-model="phone">
			</div>
			<div class="input">
				<div class="name">地址</div>
				<input type="text" placeholder="请输入你的地址" v-model="addr">
			</div>
			<div class="login-btn" @click="confirm()">
				确定
			</div>
		</div>
	</div>

</template>

<script>

import { register } from "@/api/website";

export default {
	data() {
		return {
			name: "",
			username: "",
			password: "",
			rePassword: "",
			phone: "",
			addr: ""
		}
	},
	components: {

	},
	created() {

	},
	methods: {
		back() {
			this.$router.back()
		},
		confirm(){
			if(!this.name){
				this.$modal.msgError("请输入姓名");
				return
			}
			if(!this.username){
				this.$modal.msgError("请输入帐号");
				return
			}
			if(!this.password){
				this.$modal.msgError("请输入密码");
				return
			}
			if(/^[a-zA-Z0-9]{6}$/.test(this.password) == false){
				this.$modal.msgError("请输入六位字母数字混合密码");
				return
			}
			if(!this.rePassword){
				this.$modal.msgError("请输入密码");
				return
			}
			if(!this.phone){
				this.$modal.msgError("请输入手机号");
				return
			}
			if(/^1\d{10}$/.test(this.phone) == false){
				this.$modal.msgError("请输入正确手机号");
				return
			}
			if(!this.addr){
				this.$modal.msgError("请输入你的地址");
				return
			}

			if(this.rePassword != this.password){
				this.$modal.msgError("确认密码有误");
				return
			}

			if(this.username == this.phone){
				this.$modal.msgError("账号与手机号不能相同");
				return
			}
			register({
				"name":this.name,
				"username":this.username,
				"password":this.password,
				"phone":this.phone,
				"addr":this.addr
			}).then(response => {
				this.$router.push('/portal/login');
            });
		}
	}
};
</script>

<style scoped lang="scss"></style>